#pragma once

#include <stdint.h>
#include <mutex>
#include "uart_v2.hpp"
#include "yj_return.hpp"

class tjc_screen
{
public:
    typedef enum
    {
        tjc_screen_page_start = 0,
        tjc_screen_page_status = 1,
        tjc_screen_page_button = 2,
        tjc_screen_page_number = 3,
        tjc_screen_page_set_color = 4,
    } tjc_screen_page;

    typedef enum
    {
        tjc_set_color_jgq0 = 0,
        tjc_set_color_jgq1 = 1,
        tjc_set_color_jgq2 = 2,
        tjc_set_color_zcq0 = 3,
        tjc_set_color_zcq1 = 4,
        tjc_set_color_zcq2 = 5,
    } tjc_set_color_en;

    typedef enum
    {
        tjc_screen_status_rs485_12 = 0,
        tjc_screen_status_rs485_34 = 1,
        tjc_screen_status_rs485_5678 = 2,
        tjc_screen_status_i2c = 3,
        tjc_screen_status_spi = 4,
        tjc_screen_status_usb = 5,
        tjc_screen_status_next_page = 6,
        tjc_screen_number = 7

    } tjc_screen_status;

    typedef enum
    {
        tjc_screen_pic_big_error = 0,
        tjc_screen_pic_big_warning = 1,
        tjc_screen_pic_big_ok = 2,
        tjc_screen_pic_small_no = 3, // 白色
        tjc_screen_pic_small_error = 4,
        tjc_screen_pic_small_warning = 6,
        tjc_screen_pic_small_ok = 7,
    } tjc_screen_pic;

private:
    uart_v2 *_uart;
    std::mutex _mutex;
    std::mutex _uart_lock;

    tjc_screen_pic _rs485_12_pic;
    std::string _rs485_12_str;
    tjc_screen_pic _rs485_34_pic;
    std::string _rs485_34_str;
    tjc_screen_pic _rs485_5678_pic;
    std::string _rs485_5678_str;
    tjc_screen_pic _i2c_pic;
    std::string _i2c_str;
    tjc_screen_pic _spi_pic;
    std::string _spi_str;
    tjc_screen_pic _usb_pic;
    std::string _usb_str;

    tjc_screen_pic _next_page_pic;

    std::string _number_str;

    uint8_t _jgq_0;
    uint8_t _jgq_1;
    uint8_t _jgq_2;

    uint8_t _zcq_0;
    uint8_t _zcq_1;
    uint8_t _zcq_2;
    yj_return _config_ok_flag;
    bool _is_start;

    yj_return _init_flag;

    yj_return _set_text(std::string obj_name, std::string str_value);
    yj_return _set_pic(std::string obj_name, tjc_screen_pic pic_id);

public:
    tjc_screen(uart_v2 *uart);

    // 获取某个组件的值
    yj_return get_value(std::string obj_name, std::string obj_type, uint8_t &read_value);
    // 设置状态栏的显示条目内容
    void set_status_item(tjc_screen_status status_id, std::string status_context, tjc_screen_pic status_pic);
    // 设置显示数字
    yj_return set_number(std::string number_str);
    // 更换页面
    yj_return change_page(tjc_screen_page page);
    yj_return read_page(tjc_screen_page &page);

    yj_return fresh_status_screen();
    yj_return fresh_number_screen();
    yj_return read_start_bt(uint8_t &read_value);

    yj_return fresh_set_color_sq_screen();

    yj_return get_set_color_sq_screen(tjc_set_color_en get_witch, uint8_t &get_value);

    yj_return detect_start_falg();
    bool read_start_flag();
};